package com.dragon.refect.classload;

/**
 * 类的初始化多线程环境下演示案例
 *
 * @author dragon
 * @since 2019/11/14
 */
public class DeadLoopClassTest {

    static class DeadLoopClass {
        static {
            /*
             * 如果不加上这个if语句，编译器编译不通过
             */
            if (true) {
                System.out.println(Thread.currentThread().getName() + " init DeadLoopClass");
                while (true) {

                }
            }
        }
    }

    public static void main(String[] args) {
        Runnable script = () -> {
            System.out.println(Thread.currentThread().getName() + " start");
            DeadLoopClass deadLoopClass = new DeadLoopClass();
            System.out.println(Thread.currentThread().getName() + " run over");
        };

        Thread thread1 = new Thread(script, "thread1");
        Thread thread2 = new Thread(script, "thread2");
        thread1.start();
        thread2.start();
    }
}
